#pragma once

#include "Types.h"



namespace MemMgr
{
	class TLSFBlockHeaderHandler
	{
	public:

		friend class TLSFAllocator;

		typedef T_U32 Word;

		static const size_t HEADER_WORDS_OVERHEAD = 0x02;
		static const size_t HEADER_BYTES_OVERHEAD = HEADER_WORDS_OVERHEAD * sizeof(Word);

	private:

		TLSFBlockHeaderHandler(void); // Not implemented
		~TLSFBlockHeaderHandler(void); // Not implemented
		
		static void SetSize(Word* ioBlock, const size_t iSize);
		static void SetSizeAndFlags(Word* ioBlock, const size_t iSize, const Word iFlags);
		static void SetPrevPhysic(Word* ioBlock, Word* const iPrevPhysicBlock);
		static void SetNextFree(Word* ioBlock, Word* const iNextFreeBlock);
		static void SetPrevFree(Word* ioBlock, Word* const iprevFreeBlock);

		static void SetAsFree(Word* ioBlock);
		static void SetAsNotFree(Word* ioBlock);
		static void SetAsLastPhysic(Word* ioBlock);
		static void SetAsNotLastPhysic(Word* ioBlock);

		static size_t GetSize(const Word* iBlock);
		static Word* GetNextFree(Word* iBlock);
		static Word* GetPrevFree(Word* iBlock);
		static Word* GetPrevPhysic(Word* iBlock);
		static Word* GetNextPhysic(Word* iBlock);

		static bool IsLastPhysic(Word* iBlock);
		static bool IsFree(Word* iBlock);
	};
};